<template>
  <div class="payment-approval">
    <div class="page-header">
      <h1>付款审批</h1>
      <div class="breadcrumb">财务管理 / 付款审批</div>
    </div>

    <div class="search-action-section">
      <div class="search-form">
        <div class="form-item">
          <label>订单类型</label>
          <select v-model="searchForm.orderType">
            <option value="">请选择</option>
            <option value="采购单">采购单</option>
            <option value="销售单">销售单</option>
          </select>
        </div>
        <div class="form-item">
          <label>付款单号</label>
          <input v-model="searchForm.paymentCode" type="text" placeholder="请输入付款单号" />
        </div>
        <div class="form-item">
          <label>申请人</label>
          <input v-model="searchForm.applicant" type="text" placeholder="请输入申请人姓名" />
        </div>
        <div class="form-item">
          <label>审批状态</label>
          <select v-model="searchForm.approvalStatus">
            <option value="">请选择</option>
            <option value="0">待审批</option>
            <option value="1">已通过</option>
            <option value="2">已拒绝</option>
          </select>
        </div>
        <div class="form-buttons">
          <button class="btn btn-primary" @click="searchApprovals">查询</button>
          <button class="btn btn-secondary" @click="resetSearch">重置</button>
        </div>
      </div>

    </div>

    <div class="table-pagination-section">
      <div class="table-actions">
        <div class="batch-approval">
          <label class="checkbox-label">
            <input type="checkbox" v-model="selectAll" @change="toggleSelectAll" />
            <span>全选</span>
          </label>
          <button
            class="btn"
            :class="hasSelectedApprovals ? 'btn-success' : 'btn-disabled'"
            @click="batchApprove"
            :disabled="!hasSelectedApprovals"
          >
            <span class="btn-icon">✅</span>
            批量审批
          </button>
        </div>
      </div>

      <div class="table-container">
        <table class="data-table">
          <thead>
            <tr>
              <th><input type="checkbox" v-model="selectAll" @change="toggleSelectAll" /></th>
              <th>付款单号</th>
              <th>本次付款金额</th>
              <th>供应商/客户</th>
              <th>提交人</th>
              <th>提交时间</th>
              <th>审批状态</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="approval in approvalList" :key="approval.id" :class="{ 'selected-row': approval.selected }" @click="toggleRowSelect(approval, $event)">
              <td><input type="checkbox" v-model="approval.selected" @click.stop /></td>
              <td>{{ approval.paymentCode }}</td>
              <td>{{ approval.applicationAmount }}元</td>
              <td>{{ approval.supplierCustomer }}</td>
              <td>{{ approval.applicant }}</td>
              <td>{{ formatDateTime(approval.applicantTime) }}</td>
              <td>
                <span :class="getStatusClass(approval.status)">{{ getStatusText(approval.status) }}</span>
              </td>
              <td>
                <button v-if="approval.status === 0" class="btn btn-small btn-success" @click="approvePayment(approval.id)">
                  <span class="btn-icon">✅</span>
                  通过
                </button>
                <button v-if="approval.status === 0" class="btn btn-small btn-danger" @click="rejectPayment(approval.id)">
                  <span class="btn-icon">❌</span>
                  拒绝
                </button>
                <button class="btn btn-small btn-primary" @click="viewDetail(approval)">
                  <span class="btn-icon">🔍</span>
                  查看
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="pagination">
        <div class="pagination-info">共{{ totalPages }}页/{{ totalItems }}条数据</div>
        <div class="pagination-controls">
          <button class="btn btn-page" :disabled="currentPage === 1" @click="changePage(currentPage - 1)">上一页</button>
          <button v-for="page in visiblePages" :key="page" class="btn btn-page" :class="{ active: page === currentPage }" @click="changePage(page)">{{ page }}</button>
          <button class="btn btn-page" :disabled="currentPage === totalPages" @click="changePage(currentPage + 1)">下一页</button>
        </div>
      </div>
    </div>

    <!-- 查看详情弹窗 -->
    <div v-if="showDetailModal" class="modal-overlay" @click="showDetailModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>付款申请详情</h3>
          <button class="modal-close" @click="showDetailModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="detail-grid">
            <div class="detail-item">
              <label>付款单号：</label>
              <span>{{ selectedApproval.paymentCode }}</span>
            </div>
            <div class="detail-item">
              <label>申请付款金额：</label>
              <span>{{ selectedApproval.applicationAmount }}元</span>
            </div>
            <div class="detail-item">
              <label>申请日期：</label>
              <span>{{ selectedApproval.applicationDate || selectedApproval.applicantTime?.split('T')[0] || '-' }}</span>
            </div>
            <div class="detail-item">
              <label>付款方式：</label>
              <span>{{ selectedApproval.paymentMethod }}</span>
            </div>
            <div class="detail-item">
              <label>订单类型：</label>
              <span>{{ selectedApproval.orderType }}</span>
            </div>
            <div class="detail-item">
              <label>订单号：</label>
              <span>{{ selectedApproval.orderNumber }}</span>
            </div>
            <div class="detail-item">
              <label>供应商/客户：</label>
              <span>{{ selectedApproval.supplierCustomer }}</span>
            </div>
            <div class="detail-item">
              <label>总金额：</label>
              <span>{{ selectedApproval.totalAmount }}元</span>
            </div>
            <div class="detail-item">
              <label>待付款金额：</label>
              <span>{{ selectedApproval.totalAmount - selectedApproval.applicationAmount }}元</span>
            </div>
            <div class="detail-item">
              <label>采购/销售退货日期：</label>
              <span>{{ selectedApproval.orderDate || '-' }}</span>
            </div>
            <div class="detail-item">
              <label>提交人：</label>
              <span>{{ selectedApproval.applicant }}</span>
            </div>
            <div class="detail-item">
              <label>提交时间：</label>
              <span>{{ formatDateTime(selectedApproval.applicantTime) }}</span>
            </div>
            <div class="detail-item full-width">
              <label>备注：</label>
              <span>{{ selectedApproval.remark || '-' }}</span>
            </div>
            <div v-if="selectedApproval.approver" class="detail-item">
              <label>审批人：</label>
              <span>{{ selectedApproval.approver }}</span>
            </div>
            <div v-if="selectedApproval.approveTime" class="detail-item">
              <label>审批时间：</label>
              <span>{{ formatDateTime(selectedApproval.approveTime) }}</span>
            </div>
            <div v-if="selectedApproval.approveRemark" class="detail-item full-width">
              <label>审批备注：</label>
              <span>{{ selectedApproval.approveRemark }}</span>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" @click="showDetailModal = false">关闭</button>
        </div>
      </div>
    </div>

    <!-- 批量审批弹窗 -->
    <div v-if="showBatchModal" class="modal-overlay" @click="showBatchModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>批量审批</h3>
          <button class="modal-close" @click="showBatchModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="batch-info">
            <p>已选择 <strong>{{ selectedApprovals.length }}</strong> 条付款申请进行批量审批</p>
          </div>
          <div class="batch-table-container">
            <table class="batch-table">
              <thead>
                <tr>
                  <th>付款单号</th>
                  <th>本次付款金额</th>
                  <th>供应商/客户</th>
                  <th>提交人</th>
                  <th>提交时间</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="approval in selectedApprovals" :key="approval.id">
                  <td>{{ approval.paymentCode }}</td>
                  <td>{{ approval.applicationAmount }}元</td>
                  <td>{{ approval.supplierCustomer }}</td>
                  <td>{{ approval.applicant }}</td>
                  <td>{{ formatDateTime(approval.applicantTime) }}</td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="batch-remark">
            <label>审批备注：</label>
            <textarea v-model="batchRemark" placeholder="请输入审批备注（可选）" rows="3"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" @click="showBatchModal = false">取消</button>
          <button class="btn btn-danger" @click="batchReject">
            <span class="btn-icon">❌</span>
            批量拒绝
          </button>
          <button class="btn btn-success" @click="batchApproveConfirm">
            <span class="btn-icon">✅</span>
            批量通过
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { apiGet, apiPost } from '../../utils/api.js'

const searchForm = reactive({
  orderType: '',
  paymentCode: '',
  applicant: '',
  approvalStatus: ''
})

const approvalList = ref([])
const selectAll = ref(false)
const currentPage = ref(1)
const totalPages = ref(5)
const totalItems = ref(50)
const showDetailModal = ref(false)
const selectedApproval = ref({})
const showBatchModal = ref(false)
const batchRemark = ref('')

const visiblePages = computed(() => {
  const pages = []
  const start = Math.max(1, currentPage.value - 2)
  const end = Math.min(totalPages.value, currentPage.value + 2)
  for (let i = start; i <= end; i++) {
    pages.push(i)
  }
  return pages
})

const hasSelectedApprovals = computed(() => {
  return approvalList.value.some(approval => approval.selected)
})

const selectedApprovals = computed(() => {
  return approvalList.value.filter(approval => approval.selected)
})

const searchApprovals = async () => {

  await loadApprovalData()
}

const resetSearch = async () => {
  searchForm.orderType = ''
  searchForm.paymentCode = ''
  searchForm.applicant = ''
  searchForm.approvalStatus = ''
  await loadApprovalData()
}

const toggleSelectAll = () => {
  approvalList.value.forEach(approval => {
    approval.selected = selectAll.value
  })
}

const changePage = async (page) => {
  currentPage.value = page
  await loadApprovalData()
}

const getStatusClass = (status) => {
  switch (status) {
    case 0: return 'status-pending'
    case 1: return 'status-approved'
    case 2: return 'status-rejected'
    default: return ''
  }
}

const getStatusText = (status) => {
  switch (status) {
    case 0: return '待审批'
    case 1: return '已通过'
    case 2: return '已拒绝'
    default: return status
  }
}

const formatDateTime = (dateTime) => {
  if (!dateTime) return '-'
  const date = new Date(dateTime)
  return date.toLocaleString('zh-CN')
}

const toggleRowSelect = (approval, event) => {
  const target = event?.target
  if (!target) {
    approval.selected = !approval.selected
    return
  }
  const tag = target.tagName?.toLowerCase()
  if (tag === 'input' || tag === 'button' || tag === 'a') return
  if (target.closest && target.closest('button')) return
  approval.selected = !approval.selected
}

const batchApprove = () => {
  if (selectedApprovals.value.length === 0) {
    alert('请先选择要审批的付款申请')
    return
  }
  showBatchModal.value = true
}

const batchApproveConfirm = async () => {
  try {
    const promises = selectedApprovals.value.map(approval => {
      if (approval.approvalType === 'order') {
        // 订单付款审批
        return apiPost(`/finance/order-payments/${approval.id}/approve`, {
          approver: 'admin',
          approveRemark: batchRemark.value
        })
      } else {
        // 手动付款审批
        return apiPost(`/finance/payment-approvals/${approval.id}/approve`, {
          approver: 'admin',
          approveRemark: batchRemark.value
        })
      }
    })

    await Promise.all(promises)

    alert('批量审批成功！')
    showBatchModal.value = false
    batchRemark.value = ''
    await loadApprovalData()
  } catch (error) {
    console.error('批量审批失败:', error)
    alert('批量审批失败: ' + error.message)
  }
}

const batchReject = async () => {
  try {
    const promises = selectedApprovals.value.map(approval => {
      if (approval.approvalType === 'order') {
        // 订单付款驳回
        return apiPost(`/finance/order-payments/${approval.id}/reject`, {
          rejector: 'admin',
          rejectRemark: batchRemark.value
        })
      } else {
        // 手动付款驳回
        return apiPost(`/finance/payment-approvals/${approval.id}/reject`, {
          rejector: 'admin',
          rejectRemark: batchRemark.value
        })
      }
    })

    await Promise.all(promises)

    alert('批量拒绝成功！')
    showBatchModal.value = false
    batchRemark.value = ''
    await loadApprovalData()
  } catch (error) {
    console.error('批量拒绝失败:', error)
    alert('批量拒绝失败: ' + error.message)
  }
}

const approvePayment = async (id) => {
  if (!confirm('确定要批准这个付款申请吗？')) return

  try {
    // 根据审批类型调用不同的API
    const approval = approvalList.value.find(a => a.id === id)
    let result

    if (approval.approvalType === 'order') {
      // 订单付款审批
      result = await apiPost(`/finance/order-payments/${id}/approve`, {
        approver: 'admin',
        approveRemark: '审批通过'
      })
    } else {
      // 手动付款审批
      result = await apiPost(`/finance/payment-approvals/${id}/approve`, {
        approver: 'admin',
        approveRemark: '审批通过'
      })
    }

    if (result.success) {
      alert('付款申请已批准')
      await loadApprovalData()
    } else {
      alert(result.message || '批准失败')
    }
  } catch (error) {
    console.error('批准付款申请时出错:', error)
    alert('批准失败')
  }
}

const rejectPayment = async (id) => {
  if (!confirm('确定要拒绝这个付款申请吗？')) return

  try {
    // 根据审批类型调用不同的API
    const approval = approvalList.value.find(a => a.id === id)
    let result

    if (approval.approvalType === 'order') {
      // 订单付款驳回
      result = await apiPost(`/finance/order-payments/${id}/reject`, {
        rejector: 'admin',
        rejectRemark: '审批拒绝'
      })
    } else {
      // 手动付款驳回
      result = await apiPost(`/finance/payment-approvals/${id}/reject`, {
        rejector: 'admin',
        rejectRemark: '审批拒绝'
      })
    }

    if (result.success) {
      alert('付款申请已拒绝')
      await loadApprovalData()
    } else {
      alert(result.message || '拒绝失败')
    }
  } catch (error) {
    console.error('拒绝付款申请时出错:', error)
    alert('拒绝失败')
  }
}

const viewDetail = (approval) => {
  selectedApproval.value = approval
  showDetailModal.value = true
}

const loadApprovalData = async () => {
  try {
    const params = new URLSearchParams({
      page: currentPage.value,
      size: 10,
      ...(searchForm.applicant && { applicant: searchForm.applicant }),
      ...(searchForm.approvalStatus && { approvalStatus: searchForm.approvalStatus })
    })

    // 获取手动付款的审批申请
    const manualApprovals = await apiGet(`/finance/payment-approvals?${params}`)

    // 获取订单付款的审批申请（已申请但未审批的）
    const orderApprovals = await apiGet(`/finance/order-payments?${params}`)

    const allApprovals = []

    // 处理手动付款审批申请
    if (manualApprovals.content) {
      manualApprovals.content.forEach(approval => {
        allApprovals.push({
          id: approval.id,
          paymentCode: approval.approvalCode,
          applicationAmount: approval.applicationAmount,
          supplierCustomer: approval.supplierName || approval.customerName,
          applicant: approval.applicant,
          applicantTime: approval.applicantTime,
          paymentMethod: approval.paymentMethod,
          orderType: approval.orderType,
          orderNumber: approval.orderCode,
          totalAmount: approval.totalAmount,
          orderDate: approval.applicationDate,
          status: approval.status,
          approvalType: 'manual',
          selected: false
        })
      })
    }

    // 处理订单付款审批申请
    if (orderApprovals.content) {
      orderApprovals.content.forEach(order => {
        // 只显示已申请但未审批的订单
        if (order.applicationStatus === 1) { // 已申请状态
          allApprovals.push({
                      id: order.id,
          paymentCode: order.orderNumber,
          applicationAmount: order.applicationAmount,
          supplierCustomer: order.supplierCustomerName,
          applicant: order.applicant,
          applicantTime: order.applicationTime,
          paymentMethod: order.paymentMethod,
          orderType: order.orderType === 1 ? '采购单' : '退货单',
          orderNumber: order.orderNumber,
          totalAmount: order.totalAmount,
          orderDate: order.orderDate,
          status: 0, // 待审批状态
          approvalType: 'order',
          selected: false
          })
        }
      })
    }

    // 分页处理
    const startIndex = (currentPage.value - 1) * 10
    const endIndex = startIndex + 10
    approvalList.value = allApprovals.slice(startIndex, endIndex)

    totalItems.value = allApprovals.length
    totalPages.value = Math.ceil(allApprovals.length / 10)

    // 如果没有数据，使用模拟数据
    if (allApprovals.length === 0) {
      approvalList.value = Array.from({ length: 10 }, (_, index) => ({
        id: index + 1,
        selected: false,
        paymentCode: `FK${String(index + 1).padStart(3, '0')}`,
        applicationAmount: 3000.00,
        paymentMethod: '支付宝',
        orderType: '采购单',
        orderNumber: `CG${String(index + 1).padStart(4, '0')}`,
        supplierCustomer: 'XXX有限公司',
        totalAmount: 5000.00,
        orderDate: '2024-08-23',
        applicant: '夏油杰',
        applicantTime: '2024-08-23 10:30:00',
        status: 0
      }))
    }
  } catch (error) {
    console.error('加载付款审批列表时出错:', error)
    approvalList.value = Array.from({ length: 10 }, (_, index) => ({
      id: index + 1,
      selected: false,
      paymentCode: `FK${String(index + 1).padStart(3, '0')}`,
      applicationAmount: 3000.00,
      paymentMethod: '支付宝',
      orderType: '采购单',
      orderNumber: `CG${String(index + 1).padStart(4, '0')}`,
      supplierCustomer: 'XXX有限公司',
      totalAmount: 5000.00,
      orderDate: '2024-08-23',
      applicant: '夏油杰',
      applicantTime: '2024-08-23 10:30:00',
      status: 0
    }))
  }
}

onMounted(() => {
  loadApprovalData()
})
</script>

<style scoped>
.payment-approval {
  padding: 20px;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  position: relative;
}

.payment-approval::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="50" cy="10" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="10" cy="60" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="90" cy="40" r="0.5" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
  opacity: 0.3;
  pointer-events: none;
}

.page-header {
  margin-bottom: 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 25px 30px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

.page-header h1 {
  margin: 0 0 10px 0;
  font-size: 28px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.breadcrumb {
  color: rgba(255,255,255,0.9);
  font-size: 14px;
  font-weight: 500;
}

.search-action-section {
  background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 100%);
  padding: 25px 30px;
  border-radius: 16px;
  margin-bottom: 30px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  position: relative;
  overflow: hidden;
}

.search-action-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
}

.search-form {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-item label {
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-item input,
.form-item select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  min-width: 150px;
}

.form-buttons {
  display: flex;
  gap: 10px;
}

.table-pagination-section {
  background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 100%);
  padding: 25px 30px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  position: relative;
  overflow: hidden;
}

.table-pagination-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
}

.table-actions {
  padding: 15px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.batch-approval {
  display: flex;
  align-items: center;
  gap: 15px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  color: #495057;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #667eea;
}

.table-container {
  overflow-x: auto;
  margin-bottom: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.data-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #495057;
  padding: 16px 12px;
  border: none;
  position: relative;
  border-bottom: 2px solid #e9ecef;
}

.data-table tbody tr {
  transition: all 0.3s ease;
  border-bottom: 1px solid rgba(225, 229, 233, 0.5);
}

.data-table tbody tr:hover {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.data-table tbody tr.selected-row {
  background: linear-gradient(135deg, rgba(40, 167, 69, 0.08) 0%, rgba(32, 201, 151, 0.08) 100%);
  border-left: 4px solid #20c997;
  box-shadow: inset 0 0 0 1px rgba(32, 201, 151, 0.25);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.status-pending {
  color: #ffc107;
  font-weight: 600;
  background: rgba(255, 193, 7, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 193, 7, 0.3);
  display: inline-block;
}

.status-approved {
  color: #28a745;
  font-weight: 600;
  background: rgba(40, 167, 69, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(40, 167, 69, 0.3);
  display: inline-block;
}

.status-rejected {
  color: #dc3545;
  font-weight: 600;
  background: rgba(220, 53, 69, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(220, 53, 69, 0.3);
  display: inline-block;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
}

.pagination-info {
  color: #666;
  font-size: 14px;
}

.pagination-controls {
  display: flex;
  gap: 5px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

.btn-icon {
  font-size: 16px;
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: white;
  border: none;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #5a6268 0%, #3d4448 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  color: white;
  border: none;
}

.btn-success:hover {
  background: linear-gradient(135deg, #218838 0%, #1ea085 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.btn-disabled {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: rgba(255, 255, 255, 0.6);
  border: none;
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-disabled:hover {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  transform: none;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-danger {
  background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
  color: white;
  border: none;
}

.btn-danger:hover {
  background: linear-gradient(135deg, #c82333 0%, #e55a00 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
}

.btn-page {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 1px solid #e9ecef;
  color: #333;
  padding: 8px 16px;
  border-radius: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.btn-page:hover {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.btn-page.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: #667eea;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-page:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
  margin-right: 5px;
  min-width: 60px;
}

/* 弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.9) 100%);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  position: relative;
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
}

.modal-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.modal-close:hover {
  background: rgba(255,255,255,0.2);
  transform: rotate(90deg);
}

.modal-body {
  padding: 25px;
  max-height: 60vh;
  overflow-y: auto;
}

.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-item.full-width {
  grid-column: 1 / -1;
}

.detail-item label {
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.detail-item span {
  color: #666;
  font-size: 14px;
  padding: 8px 12px;
  background: rgba(102, 126, 234, 0.1);
  border-radius: 6px;
  border-left: 3px solid #667eea;
}

.modal-footer {
  padding: 20px 25px;
  background: #f8f9fa;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid #e9ecef;
}

/* 批量审批弹窗样式 */
.batch-info {
  margin-bottom: 20px;
  padding: 15px;
  background: rgba(102, 126, 234, 0.1);
  border-radius: 8px;
  border-left: 4px solid #667eea;
}

.batch-info p {
  margin: 0;
  color: #495057;
  font-weight: 500;
}

.batch-table-container {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 20px;
  border: 1px solid #e9ecef;
  border-radius: 8px;
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.batch-table th,
.batch-table td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.batch-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #495057;
  padding: 16px 12px;
  border: none;
  position: relative;
  border-bottom: 2px solid #e9ecef;
}

.batch-table tbody tr {
  transition: all 0.3s ease;
  border-bottom: 1px solid rgba(225, 229, 233, 0.5);
}

.batch-table tbody tr:hover {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
}

.batch-table tbody tr:last-child {
  border-bottom: none;
}

.batch-remark {
  margin-top: 20px;
}

.batch-remark label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
}

.batch-remark textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.batch-remark textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
</style>
